<template>
	<view class="content">
		<view class="title" style="margin-top: 100rpx;">你的标签是？</view>

		<view class="cell">
			<view class="label">自我描述</view>
			<view>
				<u-tag class="tag" v-for="(item, index) in gxTags" :text="item.name" shape="circle" :type="1==item.isselect?'primary': 'info'" @click="onItemClick(item, index)"/>
			</view>
		</view>
		
		<view class="cell">
			<view class="label">兴趣爱好</view>
			<view>
				<u-tag class="tag" v-for="(item, index) in xqTags" :text="item.name" shape="circle" :type="1==item.isselect?'primary': 'info'" @click="onItemClick(item, index)"/>
			</view>
		</view>
		
		<view class="bottom" style="margin-top: 20rpx;">
			<view @click="back">
				<u-icon name="arrow-leftward" color="#222" size="50"></u-icon>
			</view>
			<view class="btn" @click="next">
				<view class="bin-confirm">OK了</view>
				<u-icon name="arrow-rightward" color="#fff" size="28"></u-icon>
			</view>
		</view>
	</view>
</template>

<script>
	import address from '@/common/address.js';
	export default {
		data() {
			return {
				userId: '',
				gxTags: [],
				xqTags: []
			};
		},
		
		onLoad() {
			this.userId = uni.getStorageSync('userId');
			this.requestList();
		},

		methods: {
			back() {
				uni.navigateBack();
			},
			next() {
				this.requestSave();
			},
			async requestList(){
				let res = await this.$common.post("/app/user/getBiaoqian");
				if(0 == res.code){
					let data = res.data;
					this.gxTags = data.gexing;
					this.xqTags = data.xingqu;
				}else{
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
				}
			},
			async requestSave(){
				let ids = '';
				let names = '';
				this.gxTags.forEach(item=>{
					if(1==item.isselect){
						if('' == ids){
							ids = item.id;
							names = item.name;
						}else{
							ids += ','+item.id;
							names += ','+item.name;
						}
					}
				})
				this.xqTags.forEach(item=>{
					if(1==item.isselect){
						if('' == ids){
							ids = item.id;
							names = item.name;
						}else{
							ids += ','+item.id;
							names += ','+item.name;
						}
					}
				})
				
				if('' == ids){
					uni.showToast({
						title:'请选择',
						icon: 'none'
					})
					return
				}
				
				let res = await this.$common.post("/app/geren/upBiaoqian", {biaoqian: ids});
				if(0 == res.code){
					let data = res.data;
					uni.showToast({
						title: '添加成功,欢迎进入',
						icon: 'none'
					})
					setTimeout(()=>{
						uni.setStorageSync('login', true);
						uni.switchTab({
							// url:'/pages/tab/home/home',
							url:'/pages/tab/game/game',
						});
					}, 500)
				}else{
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
				}
			},
			
			onItemClick(item, index){
				item.isselect = item.isselect == 1? 2: 1;
			}
		}
	};
</script>

<style lang="scss">
	.content {
		width: 100wh;
		height: 100vh;
		margin: 0 50rpx;

		.title {
			font-weight: bold;
			font-size: 48rpx;
			color: #222;
		}

		.bottom {
			display: flex;
			flex-direction: row;
			justify-content: space-between;

			.btn {
				display: flex;
				flex-direction: row;
				justify-content: center;
				align-items: center;
				width: 150rpx;
				height: 80rpx;
				background-color: #222;
				border-radius: 10rpx;

				.bin-confirm {
					color: white;
					font-size: 24rpx;
				}
			}
		}

		.cell{
			display: flex;
			flex-direction: column;
			background-color: #fff;
			border-radius: 15rpx;
			padding: 20rpx;
			margin-top: 20rpx;
			.label{
				font-size: 36rpx;
				color: #222;
			}
			.tag{
				margin: 5rpx;
			}
		}
		
	}
</style>